package org.darcy.controller.sys;

import java.util.List;

import org.darcy.entity.sys.SysArea;
import org.darcy.framework.model.PageData;
import org.darcy.framework.model.PageParam;
import org.darcy.framework.model.R;
import org.darcy.service.sys.SysAreaService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.extern.slf4j.Slf4j;

@Tag(name = "SysArea接口：行政区域")
@RestController
@RequestMapping("/SysArea")
@Slf4j
public class SysAreaController {

	private final String info_prefix = "[行政区域模块]";

	@Autowired
	private SysAreaService SysAreaService;

	@Operation(summary = "行政区域分页列表")
	@PostMapping(value = "list")
	public R list(@RequestBody PageParam<SysArea> param) {
		log.debug("{}-列表数据", info_prefix);
		PageData<SysArea> data = SysAreaService.page(param);
		return R.ok().data(data);
	}

	@Operation(summary = "行政区域详情")
	@GetMapping("/view/{id}")
	public R view(@PathVariable Integer id) {
		log.debug("{}-查看采样计划信息", info_prefix);
		SysArea data = SysAreaService.getDetail(id);
		return R.ok().data(data);
	}

	@Operation(summary = "通过父编码得到区域列表")
	@GetMapping(value = "/getChildren/{pcode}")
	public R getChildren(@PathVariable String pcode) {
		List<SysArea> data = SysAreaService.getChildren(pcode);
		return R.ok().data(data);
	}

}
